#include "head.h"

int main(int argc,char*argv[])
{
    GtkWidget *window;//主窗口
    GtkWidget *window1;//登录窗口
    GtkWidget *box;
    GtkWidget *box1;
    GtkWidget *box1_1;
    GtkWidget *label1_1;
    GtkWidget *entry1_1;
    GtkWidget *button1;
    GtkWidget *menubar;
    GtkWidget *rootmenu;
    GtkWidget *filemenu;//文件菜单
    GtkWidget *findmenu;//查询菜单
    GtkWidget *countmenu;//统计菜单
    GtkWidget *helpmenu;//帮助菜单
    GtkWidget *menuitem;//菜单项
    GtkWidget *menuitem1;
    GtkWidget *menuitem2;
    GtkWidget *toolbar;//工具栏
    GtkWidget *image;
    GtkToolItem *toolbutton;
    GtkWidget *hbox;
    GtkWidget *h_button1;
    GtkWidget *h_button2;
    GtkWidget *h_button3;
    GtkWidget *h_button4;
    GtkWidget *h_button5;
    GtkTreeSelection *select;
    GtkWidget *scrollwindow;

    struct password p1;
    struct tree_list1 t1;
    struct list1_new_add l1;
    head=NULL;
    struct list1_teacherwork lt1;
    struct file s;
    struct file s1;
    struct myfind f;
    struct myfind f1;
    struct money m;
    struct mytime m1;
    struct mytime m2;

    e_0.module2=NULL;
    md.module2=NULL;
    mi.module2=NULL;

    //获取初始密码
    strcpy(p1.filename,"password.txt");
    p1.fp=fopen(p1.filename,"r+");
    if(feof(p1.fp))
    {
        strcpy(p1.pre_password,"123456");
        fprintf(p1.fp,"%s",p1.pre_password);
    }
    else
        fscanf(p1.fp,"%s",p1.pre_password);
    fclose(p1.fp);

    //创建主窗口并且设置对应属性
    gtk_init(&argc,&argv);
    window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
    g_signal_connect(G_OBJECT(window),"destroy",G_CALLBACK(gtk_main_quit),NULL);
    gtk_window_set_title(GTK_WINDOW(window),"教师信息管理系统");
    gtk_window_resize(GTK_WINDOW(window),590,450);
    gtk_window_set_position(GTK_WINDOW(window),GTK_WIN_POS_CENTER);
    s.window=window;
    s1.window=window;

    //创建菜单条
    box=gtk_vbox_new(FALSE,0);
    gtk_container_add(GTK_CONTAINER(window),box);
    menubar=gtk_menu_bar_new();
    gtk_box_pack_start(GTK_BOX(box),menubar,FALSE,FALSE,0);
    //创建文件菜单
    rootmenu = gtk_menu_item_new_with_label("文件     ");
    gtk_menu_shell_append(GTK_MENU_SHELL(menubar),rootmenu);
    filemenu = gtk_menu_new();
    gtk_menu_item_set_submenu(GTK_MENU_ITEM(rootmenu),filemenu);
    //创建新建菜单项
    menuitem = gtk_image_menu_item_new_from_stock(GTK_STOCK_NEW,NULL);
    gtk_menu_shell_append(GTK_MENU_SHELL(filemenu),menuitem);
    g_signal_connect(G_OBJECT(menuitem),"activate",G_CALLBACK(click_new),&t1);
    gtk_widget_show(menuitem);



    //创建打开菜单项
    menuitem = gtk_image_menu_item_new_from_stock(GTK_STOCK_OPEN,NULL);
    gtk_menu_shell_append(GTK_MENU_SHELL(filemenu),menuitem);
    g_signal_connect(G_OBJECT(menuitem),"activate",G_CALLBACK(open_files),&s1);
    gtk_widget_show(menuitem);



    //创建保存菜单项
    menuitem = gtk_image_menu_item_new_from_stock(GTK_STOCK_SAVE,NULL);
    gtk_menu_shell_append(GTK_MENU_SHELL(filemenu),menuitem);
    g_signal_connect(G_OBJECT(menuitem),"activate",G_CALLBACK(save_file),&s);
    gtk_widget_show(menuitem);



    //创建菜单横线
    menuitem = gtk_separator_menu_item_new();
    gtk_menu_shell_append(GTK_MENU_SHELL(filemenu),menuitem);
    gtk_widget_show(menuitem);



    //创建退出菜单项
    menuitem = gtk_image_menu_item_new_from_stock(GTK_STOCK_QUIT,NULL);
    gtk_menu_shell_append(GTK_MENU_SHELL(filemenu),menuitem);
    g_signal_connect(G_OBJECT(menuitem),"activate",G_CALLBACK(gtk_main_quit),NULL);
    gtk_widget_show(menuitem);
    gtk_widget_show(filemenu);
    gtk_widget_show(rootmenu);



    //创建查询菜单
    rootmenu = gtk_menu_item_new_with_label("查询     ");
    gtk_menu_shell_append(GTK_MENU_SHELL(menubar),rootmenu);
    findmenu = gtk_menu_new();
    gtk_menu_item_set_submenu(GTK_MENU_ITEM(rootmenu),findmenu);
    //创建按姓名搜索
    menuitem1=gtk_menu_item_new_with_label("按姓名查询");
    gtk_menu_shell_append(GTK_MENU_SHELL(findmenu),menuitem1);
    gtk_widget_show(menuitem1);

    //按编号搜索
    menuitem2=gtk_menu_item_new_with_label("按编号查询");
    gtk_menu_shell_append(GTK_MENU_SHELL(findmenu),menuitem2);
    gtk_widget_show(menuitem2);
    gtk_widget_show(findmenu);
    gtk_widget_show(rootmenu);




    //创建统计菜单
    rootmenu = gtk_menu_item_new_with_label("统计     ");
    gtk_menu_shell_append(GTK_MENU_SHELL(menubar),rootmenu);
    countmenu = gtk_menu_new();
    gtk_menu_item_set_submenu(GTK_MENU_ITEM(rootmenu),countmenu);
    //创建总科研经费菜单项
    menuitem = gtk_menu_item_new_with_label("总科研经费");
    gtk_menu_shell_append(GTK_MENU_SHELL(countmenu),menuitem);
    g_signal_connect(G_OBJECT(menuitem),"activate",G_CALLBACK(count_money),&m);
    gtk_widget_show(menuitem);



    //创建年度教学总学时菜单项
    menuitem = gtk_menu_item_new_with_label("教学总学时");
    gtk_menu_shell_append(GTK_MENU_SHELL(countmenu),menuitem);
    g_signal_connect(G_OBJECT(menuitem),"activate",G_CALLBACK(input_year),&m1);
    gtk_widget_show(menuitem);



    //创建年度教学工作量未达标菜单项
    menuitem = gtk_menu_item_new_with_label("教学工作量未达标");
    gtk_menu_shell_append(GTK_MENU_SHELL(countmenu),menuitem);
    g_signal_connect(G_OBJECT(menuitem),"activate",G_CALLBACK(input_content),&m2);
    gtk_widget_show(menuitem);
    gtk_widget_show(countmenu);
    gtk_widget_show(rootmenu);




    //创建帮助菜单
    rootmenu = gtk_menu_item_new_with_label("帮助     ");
    gtk_menu_shell_append(GTK_MENU_SHELL(menubar),rootmenu);
    helpmenu = gtk_menu_new();
    gtk_menu_item_set_submenu(GTK_MENU_ITEM(rootmenu),helpmenu);
    //创建关于菜单项
    menuitem = gtk_image_menu_item_new_from_stock(GTK_STOCK_ABOUT,NULL);
    g_signal_connect(G_OBJECT(menuitem),"activate",G_CALLBACK(about_dialog),NULL);
    gtk_menu_shell_append(GTK_MENU_SHELL(helpmenu),menuitem);
    gtk_widget_show(menuitem);

    //创建修改密码菜单项
    menuitem=gtk_image_menu_item_new_with_label("修改密码");
    image=gtk_image_new_from_stock(GTK_STOCK_EDIT,GTK_ICON_SIZE_MENU);
    gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(menuitem),image);
    g_signal_connect(G_OBJECT(menuitem),"activate",G_CALLBACK(edit_password),&p1);
    gtk_menu_shell_append(GTK_MENU_SHELL(helpmenu),menuitem);
    gtk_widget_show(menuitem);
    gtk_widget_show(helpmenu);
    gtk_widget_show(rootmenu);



    gtk_widget_show(menubar);
    gtk_widget_show(box);

    //创建工具栏
    toolbar = gtk_toolbar_new();
    gtk_box_pack_start(GTK_BOX(box),toolbar,FALSE,FALSE,0);

    //创建新建按钮
    toolbutton = gtk_tool_button_new_from_stock (GTK_STOCK_NEW);
    gtk_toolbar_insert(GTK_TOOLBAR(toolbar),toolbutton,0);
    g_signal_connect(G_OBJECT(toolbutton),"clicked",G_CALLBACK(click_new),&t1);
    gtk_widget_show(GTK_WIDGET(toolbutton));



    //创建打开按钮
    toolbutton = gtk_tool_button_new_from_stock (GTK_STOCK_OPEN);
    gtk_toolbar_insert(GTK_TOOLBAR(toolbar),toolbutton,1);
    g_signal_connect(G_OBJECT(toolbutton),"clicked",G_CALLBACK(open_files),&s1);
    gtk_widget_show(GTK_WIDGET(toolbutton));



    //创建保存按钮
    toolbutton = gtk_tool_button_new_from_stock (GTK_STOCK_SAVE);
    gtk_toolbar_insert(GTK_TOOLBAR(toolbar),toolbutton,2);
    g_signal_connect(G_OBJECT(toolbutton),"clicked",G_CALLBACK(save_file),&s);
    gtk_widget_show(GTK_WIDGET(toolbutton));



    //创建退出按钮
    toolbutton = gtk_tool_button_new_from_stock (GTK_STOCK_QUIT);
    gtk_toolbar_insert(GTK_TOOLBAR(toolbar),toolbutton,3);
    g_signal_connect(G_OBJECT(toolbutton),"clicked",G_CALLBACK(gtk_main_quit),NULL);
    gtk_widget_show(GTK_WIDGET(toolbutton));
    gtk_widget_show(toolbar);


    //创建滚动窗口
    scrollwindow=gtk_scrolled_window_new(NULL,NULL);
    gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrollwindow),GTK_POLICY_AUTOMATIC,GTK_POLICY_AUTOMATIC);
    gtk_box_pack_start(GTK_BOX(box),scrollwindow,TRUE,TRUE,0);
    gtk_widget_show(scrollwindow);


    //创建树视图
    treelist1=gtk_tree_view_new();
    gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scrollwindow),treelist1);
    arrange_treelist1(treelist1);
    module1=creat_module1();
    gtk_tree_view_set_model(GTK_TREE_VIEW(treelist1),module1);
    select = gtk_tree_view_get_selection (GTK_TREE_VIEW (treelist1));
    gtk_tree_selection_set_mode (select, GTK_SELECTION_SINGLE);
    t1.list1=treelist1;
    t1.module1=module1;
    l1.module1=module1;
    l1.head=&head;
    l1.entry=NULL;
    l1.entry1=NULL;
    l1.entry2=NULL;
    l1.entry3=NULL;
    lt1.select=select;
    s1.module=module1;
    s1.list1=treelist1;
    e_0.select=select;
    e_0.module=module1;
    md.select=select;
    md.module=module1;
    mi.module1=module1;
    mi.select=select;
    f.module=module1;
    f.treeview=treelist1;
    f1.module=module1;
    f1.treeview=treelist1;
    g_signal_connect(G_OBJECT(menuitem1),"activate",G_CALLBACK(find_name),&f);
    g_signal_connect(G_OBJECT(menuitem2),"activate",G_CALLBACK(find_id),&f1);

    //底部按钮
    hbox=gtk_hbox_new(FALSE,0);
    gtk_box_pack_end(GTK_BOX(box),hbox,FALSE,FALSE,0);
    //新增按钮
    h_button1=gtk_button_new_with_label("     新增     ");
    t1.button1=h_button1;
    s1.button=h_button1;
    gtk_box_pack_start(GTK_BOX(hbox),h_button1,FALSE,FALSE,5);
    g_signal_connect(G_OBJECT(h_button1),"clicked",G_CALLBACK(new_add1),&l1);
    gtk_widget_set_sensitive(h_button1,FALSE);
    gtk_widget_show(h_button1);
    //教师工作量按钮
    h_button2=gtk_button_new_with_label("  教师工作量  ");
    gtk_box_pack_start(GTK_BOX(hbox),h_button2,FALSE,FALSE,5);
    g_signal_connect(G_OBJECT(h_button2),"clicked",G_CALLBACK(list1_teacher_work),&lt1);
    gtk_widget_set_sensitive(h_button2,FALSE);
    gtk_widget_show(h_button2);

    g_signal_connect(G_OBJECT(select),"changed",G_CALLBACK(teacher_work),h_button2);

    //修改按钮
    h_button3=gtk_button_new_with_label("     修改     ");
    gtk_box_pack_start(GTK_BOX(hbox),h_button3,FALSE,FALSE,5);
    gtk_widget_set_sensitive(h_button3,FALSE);
    gtk_widget_show(h_button3);
    g_signal_connect(G_OBJECT(h_button3),"clicked",G_CALLBACK(edit_teacherinfo),&e_0);
    g_signal_connect(G_OBJECT(select),"changed",G_CALLBACK(teacher_work),h_button3);

    //删除按钮
    h_button4=gtk_button_new_with_label("     删除     ");
    gtk_box_pack_start(GTK_BOX(hbox),h_button4,FALSE,FALSE,5);
    gtk_widget_set_sensitive(h_button4,FALSE);
    g_signal_connect(G_OBJECT(h_button4),"clicked",G_CALLBACK(delete_teacherinfo),&md);
    gtk_widget_show(h_button4);
    g_signal_connect(G_OBJECT(select),"changed",G_CALLBACK(teacher_work),h_button4);

    //插入按钮
    h_button5=gtk_button_new_with_label("     插入     ");
    gtk_box_pack_start(GTK_BOX(hbox),h_button5,FALSE,FALSE,5);
    gtk_widget_set_sensitive(h_button5,FALSE);
    g_signal_connect(G_OBJECT(h_button5),"clicked",G_CALLBACK(insert_teacherinfo),&mi);
    gtk_widget_show(h_button5);
    g_signal_connect(G_OBJECT(select),"changed",G_CALLBACK(teacher_work),h_button5);
    gtk_widget_show(hbox);

    //创建登录窗口
    window1 = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    g_signal_connect(G_OBJECT(window1),"destroy",G_CALLBACK(gtk_main_quit),NULL);
    gtk_window_set_title(GTK_WINDOW(window1),"登录窗口");
    gtk_window_resize(GTK_WINDOW(window1),100,100);
    gtk_window_set_position(GTK_WINDOW(window1),GTK_WIN_POS_CENTER);
    gtk_container_set_border_width(GTK_CONTAINER(window1),20);
    box1 = gtk_vbox_new(FALSE,0);
    gtk_container_add(GTK_CONTAINER(window1),box1);
    gtk_widget_show(window1);
    //创建密码输入框
    box1_1 = gtk_hbox_new(FALSE,0);
    gtk_box_pack_start(GTK_BOX(box1),box1_1,FALSE,FALSE,5);
    label1_1 = gtk_label_new("密码:");
    gtk_box_pack_start(GTK_BOX(box1_1),label1_1,FALSE,FALSE,5);
    gtk_widget_show(label1_1);
    entry1_1 = gtk_entry_new();
    gtk_entry_set_visibility(GTK_ENTRY(entry1_1),FALSE);
    gtk_box_pack_start(GTK_BOX(box1_1),entry1_1,FALSE,FALSE,5);
    gtk_editable_set_editable (GTK_EDITABLE(entry1_1),TRUE);
    gtk_widget_show(entry1_1);
    gtk_widget_show(box1_1);

    //创建确认按钮
    button1 = gtk_button_new_with_label("确认");
    p1.entry1_1=entry1_1;
    p1.window=window;
    p1.window1=window1;
    p1.entry1=NULL;
    g_signal_connect(G_OBJECT(button1),"clicked",G_CALLBACK(pass_check),&p1);
    gtk_box_pack_start(GTK_BOX(box1),button1,FALSE,FALSE,5);
    gtk_widget_show(button1);


    gtk_widget_show(box1);

    gtk_main();
    return FALSE;
}

